package com.pro.service.impl;


import com.pro.bean.Mentor;
import com.pro.dao.MentorDao;
import com.pro.service.MentorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * (Mentor)表服务实现类
 *
 * @author makejava
 * @since 2020-12-24 11:43:40
 */
@Service("mentorService")
public class MentorServiceImpl implements MentorService {
    @Autowired
    private MentorDao mentorDao;

    //查询所有数据
    @Override
    public List<Mentor> selAll() {
        return mentorDao.selAll();
    }

    //查询所有讲师
    public List<Map<String,Object>> selMentor(){
        //调用mapper方法查询所有讲师
        List<Mentor> mentors = mentorDao.selMentor();
        List<Map<String,Object>> mentorList = new ArrayList<>(mentors.size());
        for (Mentor mentor : mentors){//将数据遍历
            Map<String,Object> m =new HashMap<>(2);
            m.put("value",mentor.getMentorId());//将每个讲师id放入m集合中
            m.put("label",mentor.getMentorName());//将每个讲师名称放入m集合中
            mentorList.add(m);//每个讲师的集合作为元素传入mentorList集合
        }
        //将所有存储着所有讲师的集合返回
        return mentorList;
    }
}